define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'qrcode', 'layer', 'upload'], function ($, undefined, Backend, Table, Form, qrcode, layer, Upload) {
 
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    ajaxOperate : ['add','edit']
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                pk: 'id',
                sortName: 'id',
                queryParams:function(params) {
                    // 要显示的字段
                    // params.fields = '';
                    // // 要关联的拓展信息
                    params.extra = 'user,customer';
                    return params;
                },
                // search:true,
                // commonSearch: true,
                // searchFormVisible: false,
                columns: [
                    [
                        // {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID',operate:false},
                        {field: '', title: '公司名称（昵称）',operate: false,align:'left',formatter: function (value, row, index) {
                            var _user = row.user || {};
                            return row.name + "("+ (typeof _user.nickname === 'string' ? _user.nickname : '-') +")";
                        }},
                        {field: 'customer.customer_realname', title: '介绍人',align:'left'},
                        {field: 'area', title: '地区',operate: false},
                        {field: 'address', title: '地址',operate: false},
                        {field: 'status_name', title: '状态'},
                        {field: 'manage_remark', title: '备注',operate: false},
                        {field: 'create_time', title: '申请时间', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'review_time', title: '审批时间', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: Controller.api.formatter.operate},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        review:function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                operate: function (value, row, index) {
                    var _operate = '';
                        _operate += '<a class="btn btn-info btn-xs btn-review">审核</a>&nbsp;';
                        _operate += '&nbsp;<a class="btn btn-danger btn-delone btn-xs"><i class="fa fa-trash"></i> 删除</a>';
                    return _operate;
                }
            },
            events:{
                operate: $.extend({
                    'click .btn-review':function(e, value, row, index) {
                        Backend.api.open(Config.root + '/user/admin.distributor/review/id/' + row.id, '审核分销商');
                    },
                }, Table.api.events.operate)
            }
        }
    }
    return Controller;
});